package JVM;

public class Single {

    private static Single sin;

    private Single(){
    }

    //懒汉式（单例模式）
    //双重检查
    public static Single getInstance(){
        if (sin==null){
            synchronized (Single.class){
                if (sin==null){
                    sin=new Single();
                }
            }
        }
        return sin;
    }

    public static void main(String[] args) {

    }
   /* public static void main(String[] args) {
        for(int i=0;i<1000;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Single.getInstance());
                }
            }).start();
        }

    }*/

    public static Single single2(){
        if (sin==null){
            synchronized (Single.class){
                if (sin==null){
                    sin=new Single();
                }
            }
        }
        return sin;
    }
}
